using System;
using System.Linq;
using System.Runtime.Serialization;
using System.Data.Objects.DataClasses;
using System.Xml.Serialization;
using System.ComponentModel;
using System.Collections.Generic;
using System.Data.Objects;
using System.Text;
using Acme.Northwind.EFDAL;
using nHydrate.EFCore.DataAccess;
using nHydrate.EFCore.EventArgs;
using System.Text.RegularExpressions;
using System.Linq.Expressions;
using System.Data.Linq;

namespace Acme.Northwind.EFDAL.Entity
{
	/// <summary>
	/// The collection to hold 'SalesTotalsbyAmount' entities
	/// </summary>
	[EdmEntityTypeAttribute(NamespaceName="Acme.Northwind.EFDAL.Entity", Name="SalesTotalsbyAmount")]
	[Serializable()]
	[DataContractAttribute(IsReference = true)]
	[nHydrate.EFCore.Attributes.FieldNameConstantsAttribute(typeof(Acme.Northwind.EFDAL.Entity.SalesTotalsbyAmount.FieldNameConstants))]
	[System.ComponentModel.ImmutableObject(true)]
	[System.CodeDom.Compiler.GeneratedCode("nHydrateModelGenerator", "5.0.1.100")]
	public partial class SalesTotalsbyAmount : nHydrate.EFCore.DataAccess.NHEntityObject, nHydrate.EFCore.DataAccess.IReadOnlyBusinessObject, Acme.Northwind.EFDAL.Interfaces.Entity.ISalesTotalsbyAmount, System.IEquatable<Acme.Northwind.EFDAL.Interfaces.Entity.ISalesTotalsbyAmount>
	{
		#region FieldNameConstants Enumeration

		/// <summary>
		/// Enumeration to define each property that maps to a database field for the 'SalesTotalsbyAmount' customView.
		/// </summary>
		public enum FieldNameConstants
		{
			/// <summary>
			/// Field mapping for the 'CompanyName' property
			/// </summary>
			[System.ComponentModel.ReadOnlyAttribute(true)]
			[System.ComponentModel.Description("Field mapping for the 'CompanyName' property")]
			CompanyName,
			/// <summary>
			/// Field mapping for the 'OrderID' property
			/// </summary>
			[System.ComponentModel.ReadOnlyAttribute(true)]
			[System.ComponentModel.Description("Field mapping for the 'OrderID' property")]
			OrderID,
			/// <summary>
			/// Field mapping for the 'SaleAmount' property
			/// </summary>
			[System.ComponentModel.ReadOnlyAttribute(true)]
			[System.ComponentModel.Description("Field mapping for the 'SaleAmount' property")]
			SaleAmount,
			/// <summary>
			/// Field mapping for the 'ShippedDate' property
			/// </summary>
			[System.ComponentModel.ReadOnlyAttribute(true)]
			[System.ComponentModel.Description("Field mapping for the 'ShippedDate' property")]
			ShippedDate,
		}
		#endregion

		#region Constructors

		/// <summary>
		/// Initializes a new instance of the Acme.Northwind.EFDAL.Entity.SalesTotalsbyAmount class
		/// </summary>
		protected internal SalesTotalsbyAmount()
		{
		}

		#endregion

		#region Properties

		[System.ComponentModel.Browsable(false)]
		[EdmScalarPropertyAttribute(EntityKeyProperty = true, IsNullable = false)]
		[DataMemberAttribute()]
		[System.ComponentModel.DisplayName("pk")]
		[System.ComponentModel.ReadOnly(true)]
		private Guid pk
		{
			get { return _pk; }
			set { _pk = value; }
		}
		private Guid _pk;

		/// <summary>
		/// </summary>
		[System.ComponentModel.Browsable(true)]
		[EdmScalarPropertyAttribute(EntityKeyProperty = false, IsNullable = false)]
		[DataMemberAttribute()]
		[System.ComponentModel.DisplayName("CompanyName")]
		[System.ComponentModel.ReadOnly(true)]
		public virtual string CompanyName
		{
			get { return _companyName; }
			set
			{
				if ((value != null) && (value.Length > GetMaxLength(FieldNameConstants.CompanyName))) throw new Exception(string.Format(GlobalValues.ERROR_DATA_TOO_BIG, value, "SalesTotalsbyAmount.CompanyName", GetMaxLength(FieldNameConstants.CompanyName)));
				var eventArg = new nHydrate.EFCore.EventArgs.ChangingEventArgs<string>(value, "CompanyName");
				//this.OnCompanyNameChanging(eventArg);
				if (eventArg.Cancel) return;
				ReportPropertyChanging("CompanyName");
				_companyName = eventArg.Value;
				ReportPropertyChanged("CompanyName");
				//this.OnCompanyNameChanged(eventArg);
			}
		}

		/// <summary>
		/// </summary>
		[System.ComponentModel.Browsable(true)]
		[EdmScalarPropertyAttribute(EntityKeyProperty = false, IsNullable = false)]
		[DataMemberAttribute()]
		[System.ComponentModel.DisplayName("OrderID")]
		[System.ComponentModel.ReadOnly(true)]
		public virtual int OrderID
		{
			get { return _orderID; }
			set
			{
				var eventArg = new nHydrate.EFCore.EventArgs.ChangingEventArgs<int>(value, "OrderID");
				//this.OnOrderIDChanging(eventArg);
				if (eventArg.Cancel) return;
				ReportPropertyChanging("OrderID");
				_orderID = eventArg.Value;
				ReportPropertyChanged("OrderID");
				//this.OnOrderIDChanged(eventArg);
			}
		}

		/// <summary>
		/// </summary>
		[System.ComponentModel.Browsable(true)]
		[EdmScalarPropertyAttribute(EntityKeyProperty = false, IsNullable = true)]
		[DataMemberAttribute()]
		[System.ComponentModel.DisplayName("SaleAmount")]
		[System.ComponentModel.ReadOnly(true)]
		public virtual decimal? SaleAmount
		{
			get { return _saleAmount; }
			set
			{
				var eventArg = new nHydrate.EFCore.EventArgs.ChangingEventArgs<decimal?>(value, "SaleAmount");
				//this.OnSaleAmountChanging(eventArg);
				if (eventArg.Cancel) return;
				ReportPropertyChanging("SaleAmount");
				_saleAmount = eventArg.Value;
				ReportPropertyChanged("SaleAmount");
				//this.OnSaleAmountChanged(eventArg);
			}
		}

		/// <summary>
		/// </summary>
		[System.ComponentModel.Browsable(true)]
		[EdmScalarPropertyAttribute(EntityKeyProperty = false, IsNullable = true)]
		[DataMemberAttribute()]
		[System.ComponentModel.DisplayName("ShippedDate")]
		[System.ComponentModel.ReadOnly(true)]
		public virtual DateTime? ShippedDate
		{
			get { return _shippedDate; }
			set
			{
				if ((value != null) && (value < GlobalValues.MIN_DATETIME)) throw new Exception("The DateTime value 'ShippedDate' (" + value.Value.ToString("yyyy-MM-dd HH:mm:ss") + ") cannot be less than " + GlobalValues.MIN_DATETIME.ToString());
				if ((value != null) && (value > GlobalValues.MAX_DATETIME)) throw new Exception("The DateTime value 'ShippedDate' (" + value.Value.ToString("yyyy-MM-dd HH:mm:ss") + ") cannot be greater than " + GlobalValues.MAX_DATETIME.ToString());
				var eventArg = new nHydrate.EFCore.EventArgs.ChangingEventArgs<DateTime?>(value, "ShippedDate");
				//this.OnShippedDateChanging(eventArg);
				if (eventArg.Cancel) return;
				ReportPropertyChanging("ShippedDate");
				_shippedDate = eventArg.Value;
				ReportPropertyChanged("ShippedDate");
				//this.OnShippedDateChanged(eventArg);
			}
		}

		#endregion

		#region Events

		/// <summary>
		/// The internal reference variable for the 'CompanyName' property
		/// </summary>
		protected string _companyName;

		/// <summary>
		/// The internal reference variable for the 'OrderID' property
		/// </summary>
		protected int _orderID;

		/// <summary>
		/// The internal reference variable for the 'SaleAmount' property
		/// </summary>
		protected decimal? _saleAmount;

		/// <summary>
		/// The internal reference variable for the 'ShippedDate' property
		/// </summary>
		protected DateTime? _shippedDate;

		#endregion

		#region GetMaxLength

		/// <summary>
		/// Gets the maximum size of the field value.
		/// </summary>
		public static int GetMaxLength(FieldNameConstants field)
		{
			switch (field)
			{
				case FieldNameConstants.CompanyName:
					return 80;
				case FieldNameConstants.OrderID:
					return 0;
				case FieldNameConstants.SaleAmount:
					return 0;
				case FieldNameConstants.ShippedDate:
					return 0;
			}
			return 0;
		}

		int nHydrate.EFCore.DataAccess.IReadOnlyBusinessObject.GetMaxLength(Enum field)
		{
			return GetMaxLength((FieldNameConstants)field);
		}

		#endregion

		#region GetFieldType

		/// <summary>
		/// Gets the system type of a field on this object
		/// </summary>
		public static System.Type GetFieldType(FieldNameConstants field)
		{
			var o = new SalesTotalsbyAmount();
			return ((nHydrate.EFCore.DataAccess.IReadOnlyBusinessObject)o).GetFieldType(field);
		}

		System.Type nHydrate.EFCore.DataAccess.IReadOnlyBusinessObject.GetFieldType(Enum field)
		{
			if (field.GetType() != typeof(FieldNameConstants))
				throw new Exception("The '" + field.GetType().ReflectedType.ToString() + ".FieldNameConstants' value is not valid. The field parameter must be of type '" + this.GetType().ToString() + ".FieldNameConstants'.");

			var array = Enum.GetValues(typeof(FieldNameConstants));
			switch ((FieldNameConstants)field)
			{
				case FieldNameConstants.CompanyName: return typeof(string);
				case FieldNameConstants.OrderID: return typeof(int);
				case FieldNameConstants.SaleAmount: return typeof(decimal?);
				case FieldNameConstants.ShippedDate: return typeof(DateTime?);
			}
			return null;
		}

		#endregion

		#region GetFieldNameConstants

		System.Type nHydrate.EFCore.DataAccess.IReadOnlyBusinessObject.GetFieldNameConstants()
		{
			return typeof(FieldNameConstants);
		}

		#endregion

		#region Get/Set Value

		object nHydrate.EFCore.DataAccess.IReadOnlyBusinessObject.GetValue(System.Enum field)
		{
			return ((nHydrate.EFCore.DataAccess.IReadOnlyBusinessObject)this).GetValue(field, null);
		}

		object nHydrate.EFCore.DataAccess.IReadOnlyBusinessObject.GetValue(System.Enum field, object defaultValue)
		{
			if (field.GetType() != typeof(FieldNameConstants))
				throw new Exception("The '" + field.GetType().ReflectedType.ToString() + ".FieldNameConstants' value is not valid. The field parameter must be of type '" + this.GetType().ToString() + ".FieldNameConstants'.");
			return this.GetValue((FieldNameConstants)field, defaultValue);
		}

		#endregion

		#region PrimaryKey

		/// <summary>
		/// Hold the primary key for this object
		/// </summary>
		protected nHydrate.EFCore.DataAccess.IPrimaryKey _primaryKey = null;
		nHydrate.EFCore.DataAccess.IPrimaryKey nHydrate.EFCore.DataAccess.IReadOnlyBusinessObject.PrimaryKey
		{
			get { return null; }
		}

		#endregion

		#region IsParented

		/// <summary>
		/// Determines if this object is part of a collection or is detached
		/// </summary>
		[System.ComponentModel.Browsable(false)]
		public virtual bool IsParented
		{
		  get { return (this.EntityState != System.Data.EntityState.Detached); }
		}

		#endregion

		#region IsEquivalent

		/// <summary>
		/// Determines if all of the fields for the specified object exactly matches the current object.
		/// </summary>
		/// <param name="item">The object to compare</param>
		public override bool IsEquivalent(nHydrate.EFCore.DataAccess.INHEntityObject item)
		{
			if (item == null) return false;
			if (!(item is Acme.Northwind.EFDAL.Interfaces.Entity.ISalesTotalsbyAmount)) return false;
			var o = item as Acme.Northwind.EFDAL.Interfaces.Entity.ISalesTotalsbyAmount;
			return (
				o.CompanyName == this.CompanyName &&
				o.OrderID == this.OrderID &&
				o.SaleAmount == this.SaleAmount &&
				o.ShippedDate == this.ShippedDate
				);
		}

		#endregion

		#region Equals
		bool System.IEquatable<Acme.Northwind.EFDAL.Interfaces.Entity.ISalesTotalsbyAmount>.Equals(Acme.Northwind.EFDAL.Interfaces.Entity.ISalesTotalsbyAmount other)
		{
			return this.IsEquivalent(other);
		}
		#endregion

		#region GetValue

		/// <summary>
		/// Gets the value of one of this object's properties.
		/// </summary>
		public object GetValue(FieldNameConstants field)
		{
			return GetValue(field, null);
		}

		/// <summary>
		/// Gets the value of one of this object's properties.
		/// </summary>
		public object GetValue(FieldNameConstants field, object defaultValue)
		{
			if (field == FieldNameConstants.CompanyName)
				return this.CompanyName;
			if (field == FieldNameConstants.OrderID)
				return this.OrderID;
			if (field == FieldNameConstants.SaleAmount)
				return ((this.SaleAmount == null) ? defaultValue : this.SaleAmount);
			if (field == FieldNameConstants.ShippedDate)
				return ((this.ShippedDate == null) ? defaultValue : this.ShippedDate);
			throw new Exception("Field '" + field.ToString() + "' not found!");
		}

		/// <summary>
		/// Gets the value of one of this object's properties.
		/// </summary>
		public int GetInteger(Acme.Northwind.EFDAL.Entity.SalesTotalsbyAmount.FieldNameConstants field)
		{
			return this.GetInteger(field, int.MinValue);
		}

		/// <summary>
		/// Gets the value of one of this object's properties.
		/// </summary>
		public int GetInteger(Acme.Northwind.EFDAL.Entity.SalesTotalsbyAmount.FieldNameConstants field, int defaultValue)
		{
			var o = this.GetValue(field, defaultValue);
			if (o is string)
			{
				int a;
				if (int.TryParse((string)o, out a))
					return a;
				else
					throw new System.InvalidCastException();
			}
			else
			{
				return (int)o;
			}
		}

		/// <summary>
		/// Gets the value of one of this object's properties.
		/// </summary>
		public double GetDouble(Acme.Northwind.EFDAL.Entity.SalesTotalsbyAmount.FieldNameConstants field)
		{
			return this.GetDouble(field, double.MinValue);
		}

		/// <summary>
		/// Gets the value of one of this object's properties.
		/// </summary>
		public double GetDouble(Acme.Northwind.EFDAL.Entity.SalesTotalsbyAmount.FieldNameConstants field, double defaultValue)
		{
			var o = this.GetValue(field, defaultValue);
			if (o is string)
			{
				double a;
				if (double.TryParse((string)o, out a))
					return a;
				else
					throw new System.InvalidCastException();
			}
			else
			{
				return (double)o;
			}
		}

		/// <summary>
		/// Gets the value of one of this object's properties.
		/// </summary>
		public System.DateTime GetDateTime(Acme.Northwind.EFDAL.Entity.SalesTotalsbyAmount.FieldNameConstants field)
		{
			return this.GetDateTime(field, System.DateTime.MinValue);
		}

		/// <summary>
		/// Gets the value of one of this object's properties.
		/// </summary>
		public System.DateTime GetDateTime(Acme.Northwind.EFDAL.Entity.SalesTotalsbyAmount.FieldNameConstants field, System.DateTime defaultValue)
		{
			var o = this.GetValue(field, defaultValue);
			if (o is string)
			{
				System.DateTime a;
				if (System.DateTime.TryParse((string)o, out a))
					return a;
				else
					throw new System.InvalidCastException();
			}
			else
			{
				return (System.DateTime)o;
			}
		}

		/// <summary>
		/// Gets the value of one of this object's properties.
		/// </summary>
		public string GetString(Acme.Northwind.EFDAL.Entity.SalesTotalsbyAmount.FieldNameConstants field)
		{
			return this.GetString(field, string.Empty);
		}

		/// <summary>
		/// Gets the value of one of this object's properties.
		/// </summary>
		public string GetString(Acme.Northwind.EFDAL.Entity.SalesTotalsbyAmount.FieldNameConstants field, string defaultValue)
		{
			var o = this.GetValue(field, defaultValue);
			if (o is string)
			{
				return (string)o;
			}
			else
			{
				return o.ToString();
			}
		}

		#endregion

		#region GetDatabaseFieldName

		/// <summary>
		/// Returns the actual database name of the specified field.
		/// </summary>
		internal static string GetDatabaseFieldName(SalesTotalsbyAmount.FieldNameConstants field)
		{
			return GetDatabaseFieldName(field.ToString());
		}

		/// <summary>
		/// Returns the actual database name of the specified field.
		/// </summary>
		internal static string GetDatabaseFieldName(string field)
		{
			switch (field)
			{
				case "CompanyName": return "CompanyName";
				case "OrderID": return "OrderID";
				case "SaleAmount": return "SaleAmount";
				case "ShippedDate": return "ShippedDate";
			}
			return string.Empty;
		}

		#endregion

	}

}

